import axios from "axios";
import {Message} from 'element-ui';

const instance = axios.create({
    baseURL: 'http://localhost:8080/',
    timeout: 10000
});

function request(url, method = "get", data = null, hasHeader = true) {
    let h = {'Authorization': localStorage.getItem("Authorization")};
    return new Promise(((resolve) => {
        instance.request({
            url, method,
            headers: hasHeader ? h : null,
            data
        }).then((resp) => {
            resolve(resp.data)
        }).catch(error => {
            if (error.response)
            Message.error(error.response.data)
            //reject(error)
        })
    }))
}

export default request